
#include"common.hpp"



void User(char* buff)
{
    std::cout<<"user should: "<<buff<<" ip port"<<std::endl;
    exit(USER_ERR);
}

int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        User(argv[0]);
    }
    std::string ip = argv[1];
    int port = std::stoi(argv[2]);
    Inetaddr addr(ip,port);

    int sfd = socket(AF_INET,SOCK_STREAM,0);
    int n = connect(sfd,(sockaddr*)&addr.Getaddr(),sizeof(addr.Getaddr()));
    if(n < 0)
    {
        LOG(level::ERROR)<<"connect false";
        exit(CONNECT_ERR);
    }
    while(1)
    {
        std::cout<<"please say# ";
        std::string wstr;
        getline(std::cin,wstr);
        ssize_t ws = write(sfd,wstr.c_str(),wstr.size());

        char buff[512];
        ssize_t rs = read(sfd,buff,sizeof(buff)-1);
        if(rs > 0){
            buff[rs] = 0;
            std::cout<<buff<<std::endl;
        }

    }

    return 0;
}
